﻿/**  版本信息模板在安装目录下，可自行修改。
* Hardware.cs
*
* 功 能： N/A
* 类 名： Hardware
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2017/2/3 10:28:10   N/A    初版
*
* Copyright (c) 2012 Maticsoft Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：动软卓越（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using DataLib.DBUtility;//Please add references

namespace DataLib.DAL
{
	/// <summary>
	/// 数据访问类:Hardware
	/// </summary>
	public partial class Hardware
	{
		public Hardware()
		{}
        #region  BasicMethod

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return DbHelperSQL.GetMaxID("id", "Hardware");
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from Hardware");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)
			};
            parameters[0].Value = id;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        ///// <summary>
        ///// 增加一条数据
        ///// </summary>
        //public int Add(DataLib.Model.Hardware model)
        //{
        //    StringBuilder strSql = new StringBuilder();
        //    tab_Num tab = new tab_Num();
        //    model.hardwareno = tab.GenNo("E", "Hardware");
        //    strSql.Append("insert into Hardware(");
        //    strSql.Append("hardwareno,initno,hardno,wrlid,wrlno,loadno,cjono,wrldate,inspectiondate,loadremark,cjoremark,initcheck,initremark,hardwarefinish,boxcount,outstime,tallyremark,flag1,flag2,flag3,flag4,step1,step2,step3,bcity,gcity,cumname,cumcode,hardremark,saleman)");
        //    strSql.Append(" values (");
        //    strSql.Append("@hardwareno,@initno,@hardno,@wrlid,@wrlno,@loadno,@cjono,@wrldate,@inspectiondate,@loadremark,@cjoremark,@initcheck,@initremark,@hardwarefinish,@boxcount,@outstime,@tallyremark,@flag1,@flag2,@flag3,@flag4,@step1,@step2,@step3,@bcity,@gcity,@cumname,@cumcode,@hardremark,@saleman)");
        //    strSql.Append(";select @@IDENTITY");
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@hardwareno", SqlDbType.VarChar,20),
        //            new SqlParameter("@initno", SqlDbType.VarChar,20),
        //            new SqlParameter("@hardno", SqlDbType.VarChar,20),
        //            new SqlParameter("@wrlid", SqlDbType.Int,4),
        //            new SqlParameter("@wrlno", SqlDbType.VarChar,200),
        //            new SqlParameter("@loadno", SqlDbType.VarChar,100),
        //            new SqlParameter("@cjono", SqlDbType.VarChar,100),
        //            new SqlParameter("@wrldate", SqlDbType.VarChar,30),
        //            new SqlParameter("@inspectiondate", SqlDbType.VarChar,30),
        //            new SqlParameter("@loadremark", SqlDbType.VarChar,200),
        //            new SqlParameter("@cjoremark", SqlDbType.VarChar,200),
        //            new SqlParameter("@initcheck", SqlDbType.VarChar,200),
        //            new SqlParameter("@initremark", SqlDbType.VarChar,200),
        //            new SqlParameter("@hardwarefinish", SqlDbType.VarChar,200),
        //            new SqlParameter("@boxcount", SqlDbType.VarChar,20),
        //            new SqlParameter("@outstime", SqlDbType.VarChar,30),
        //            new SqlParameter("@tallyremark", SqlDbType.VarChar,300),
        //            new SqlParameter("@flag1", SqlDbType.VarChar,50),
        //            new SqlParameter("@flag2", SqlDbType.VarChar,50),
        //            new SqlParameter("@flag3", SqlDbType.VarChar,50),
        //            new SqlParameter("@flag4", SqlDbType.VarChar,50),
        //            new SqlParameter("@step1", SqlDbType.Int,4),
        //            new SqlParameter("@step2", SqlDbType.Int,4),
        //            new SqlParameter("@step3", SqlDbType.Int,4),
        //            new SqlParameter("@bcity", SqlDbType.VarChar,20),
        //            new SqlParameter("@gcity", SqlDbType.VarChar,20),
        //            new SqlParameter("@cumname", SqlDbType.VarChar,100),
        //            new SqlParameter("@cumcode", SqlDbType.VarChar,100),
        //            new SqlParameter("@hardremark", SqlDbType.VarChar,200),
        //            new SqlParameter("@saleman", SqlDbType.VarChar,50)};
        //    parameters[0].Value = model.hardwareno;
        //    parameters[1].Value = model.initno;
        //    parameters[2].Value = model.hardno;
        //    parameters[3].Value = model.wrlid;
        //    parameters[4].Value = model.wrlno;
        //    parameters[5].Value = model.loadno;
        //    parameters[6].Value = model.cjono;
        //    parameters[7].Value = model.wrldate;
        //    parameters[8].Value = model.inspectiondate;
        //    parameters[9].Value = model.loadremark;
        //    parameters[10].Value = model.cjoremark;
        //    parameters[11].Value = model.initcheck;
        //    parameters[12].Value = model.initremark;
        //    parameters[13].Value = model.hardwarefinish;
        //    parameters[14].Value = model.boxcount;
        //    parameters[15].Value = model.outstime;
        //    parameters[16].Value = model.tallyremark;
        //    parameters[17].Value = model.flag1;
        //    parameters[18].Value = model.flag2;
        //    parameters[19].Value = model.flag3;
        //    parameters[20].Value = model.flag4;
        //    parameters[21].Value = model.step1;
        //    parameters[22].Value = model.step2;
        //    parameters[23].Value = model.step3;
        //    parameters[24].Value = model.bcity;
        //    parameters[25].Value = model.gcity;
        //    parameters[26].Value = model.cumname;
        //    parameters[27].Value = model.cumcode;
        //    parameters[28].Value = model.hardremark;
        //    parameters[29].Value = model.saleman;

        //    object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
        //    if (obj == null)
        //    {
        //        return 0;
        //    }
        //    else
        //    {
        //        return Convert.ToInt32(obj);
        //    }
        //}
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(DataLib.Model.Hardware model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update Hardware set ");
            strSql.Append("hardwareno=@hardwareno,");
            strSql.Append("initno=@initno,");
            strSql.Append("hardno=@hardno,");
            strSql.Append("wrlid=@wrlid,");
            strSql.Append("wrlno=@wrlno,");
            strSql.Append("loadno=@loadno,");
            strSql.Append("cjono=@cjono,");
            strSql.Append("wrldate=@wrldate,");
            strSql.Append("inspectiondate=@inspectiondate,");
            strSql.Append("loadremark=@loadremark,");
            strSql.Append("cjoremark=@cjoremark,");
            strSql.Append("initcheck=@initcheck,");
            strSql.Append("initremark=@initremark,");
            strSql.Append("hardwarefinish=@hardwarefinish,");
            strSql.Append("boxcount=@boxcount,");
            strSql.Append("outstime=@outstime,");
            strSql.Append("tallyremark=@tallyremark,");
            strSql.Append("flag1=@flag1,");
            strSql.Append("flag2=@flag2,");
            strSql.Append("flag3=@flag3,");
            strSql.Append("flag4=@flag4,");
            strSql.Append("step1=@step1,");
            strSql.Append("step2=@step2,");
            strSql.Append("step3=@step3,");
            strSql.Append("bcity=@bcity,");
            strSql.Append("gcity=@gcity,");
            strSql.Append("cumname=@cumname,");
            strSql.Append("cumcode=@cumcode,");
            strSql.Append("hardremark=@hardremark,");
            strSql.Append("saleman=@saleman,");
            strSql.Append("gocheckremark=@gocheckremark");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = {
					new SqlParameter("@hardwareno", SqlDbType.VarChar,20),
					new SqlParameter("@initno", SqlDbType.VarChar,20),
					new SqlParameter("@hardno", SqlDbType.VarChar,20),
					new SqlParameter("@wrlid", SqlDbType.Int,4),
					new SqlParameter("@wrlno", SqlDbType.VarChar,200),
					new SqlParameter("@loadno", SqlDbType.VarChar,100),
					new SqlParameter("@cjono", SqlDbType.VarChar,100),
					new SqlParameter("@wrldate", SqlDbType.VarChar,30),
					new SqlParameter("@inspectiondate", SqlDbType.VarChar,30),
					new SqlParameter("@loadremark", SqlDbType.VarChar,200),
					new SqlParameter("@cjoremark", SqlDbType.VarChar,200),
					new SqlParameter("@initcheck", SqlDbType.VarChar,200),
					new SqlParameter("@initremark", SqlDbType.VarChar,200),
					new SqlParameter("@hardwarefinish", SqlDbType.VarChar,200),
					new SqlParameter("@boxcount", SqlDbType.VarChar,20),
					new SqlParameter("@outstime", SqlDbType.VarChar,30),
					new SqlParameter("@tallyremark", SqlDbType.VarChar,300),
					new SqlParameter("@flag1", SqlDbType.VarChar,50),
					new SqlParameter("@flag2", SqlDbType.VarChar,50),
					new SqlParameter("@flag3", SqlDbType.VarChar,50),
					new SqlParameter("@flag4", SqlDbType.VarChar,50),
					new SqlParameter("@step1", SqlDbType.Int,4),
					new SqlParameter("@step2", SqlDbType.Int,4),
					new SqlParameter("@step3", SqlDbType.Int,4),
					new SqlParameter("@bcity", SqlDbType.VarChar,20),
					new SqlParameter("@gcity", SqlDbType.VarChar,20),
					new SqlParameter("@cumname", SqlDbType.VarChar,100),
					new SqlParameter("@cumcode", SqlDbType.VarChar,100),
					new SqlParameter("@hardremark", SqlDbType.VarChar,200),
					new SqlParameter("@saleman", SqlDbType.VarChar,50),
                    new SqlParameter("@gocheckremark", SqlDbType.VarChar,50),
					new SqlParameter("@id", SqlDbType.Int,4)};
            parameters[0].Value = model.hardwareno;
            parameters[1].Value = model.initno;
            parameters[2].Value = model.hardno;
            parameters[3].Value = model.wrlid;
            parameters[4].Value = model.wrlno;
            parameters[5].Value = model.loadno;
            parameters[6].Value = model.cjono;
            parameters[7].Value = model.wrldate;
            parameters[8].Value = model.inspectiondate;
            parameters[9].Value = model.loadremark;
            parameters[10].Value = model.cjoremark;
            parameters[11].Value = model.initcheck;
            parameters[12].Value = model.initremark;
            parameters[13].Value = model.hardwarefinish;
            parameters[14].Value = model.boxcount;
            parameters[15].Value = model.outstime;
            parameters[16].Value = model.tallyremark;
            parameters[17].Value = model.flag1;
            parameters[18].Value = model.flag2;
            parameters[19].Value = model.flag3;
            parameters[20].Value = model.flag4;
            parameters[21].Value = model.step1;
            parameters[22].Value = model.step2;
            parameters[23].Value = model.step3;
            parameters[24].Value = model.bcity;
            parameters[25].Value = model.gcity;
            parameters[26].Value = model.cumname;
            parameters[27].Value = model.cumcode;
            parameters[28].Value = model.hardremark;
            parameters[29].Value = model.saleman;
            parameters[30].Value = model.gocheckremark;
            parameters[31].Value = model.id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from Hardware ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)
			};
            parameters[0].Value = id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string idlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from Hardware ");
            strSql.Append(" where id in (" + idlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public DataLib.Model.Hardware GetModel(int id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 id,hardwareno,initno,hardno,wrlid,wrlno,loadno,cjono,wrldate,inspectiondate,loadremark,cjoremark,initcheck,initremark,hardwarefinish,boxcount,outstime,tallyremark,flag1,flag2,flag3,flag4,step1,step2,step3,bcity,gcity,cumname,cumcode,hardremark,saleman,gocheckremark from Hardware ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)
			};
            parameters[0].Value = id;

            DataLib.Model.Hardware model = new DataLib.Model.Hardware();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public DataLib.Model.Hardware DataRowToModel(DataRow row)
        {
            DataLib.Model.Hardware model = new DataLib.Model.Hardware();
            if (row != null)
            {
                if (row["id"] != null && row["id"].ToString() != "")
                {
                    model.id = int.Parse(row["id"].ToString());
                }
                if (row["hardwareno"] != null)
                {
                    model.hardwareno = row["hardwareno"].ToString();
                }
                if (row["initno"] != null)
                {
                    model.initno = row["initno"].ToString();
                }
                if (row["hardno"] != null)
                {
                    model.hardno = row["hardno"].ToString();
                }
                if (row["wrlid"] != null && row["wrlid"].ToString() != "")
                {
                    model.wrlid = int.Parse(row["wrlid"].ToString());
                }
                if (row["wrlno"] != null)
                {
                    model.wrlno = row["wrlno"].ToString();
                }
                if (row["loadno"] != null)
                {
                    model.loadno = row["loadno"].ToString();
                }
                if (row["cjono"] != null)
                {
                    model.cjono = row["cjono"].ToString();
                }
                if (row["wrldate"] != null)
                {
                    model.wrldate = row["wrldate"].ToString();
                }
                if (row["inspectiondate"] != null)
                {
                    model.inspectiondate = row["inspectiondate"].ToString();
                }
                if (row["loadremark"] != null)
                {
                    model.loadremark = row["loadremark"].ToString();
                }
                if (row["cjoremark"] != null)
                {
                    model.cjoremark = row["cjoremark"].ToString();
                }
                if (row["initcheck"] != null)
                {
                    model.initcheck = row["initcheck"].ToString();
                }
                if (row["initremark"] != null)
                {
                    model.initremark = row["initremark"].ToString();
                }
                if (row["hardwarefinish"] != null)
                {
                    model.hardwarefinish = row["hardwarefinish"].ToString();
                }
                if (row["boxcount"] != null)
                {
                    model.boxcount = row["boxcount"].ToString();
                }
                if (row["outstime"] != null)
                {
                    model.outstime = row["outstime"].ToString();
                }
                if (row["tallyremark"] != null)
                {
                    model.tallyremark = row["tallyremark"].ToString();
                }
                if (row["flag1"] != null)
                {
                    model.flag1 = row["flag1"].ToString();
                }
                if (row["flag2"] != null)
                {
                    model.flag2 = row["flag2"].ToString();
                }
                if (row["flag3"] != null)
                {
                    model.flag3 = row["flag3"].ToString();
                }
                if (row["flag4"] != null)
                {
                    model.flag4 = row["flag4"].ToString();
                }
                if (row["step1"] != null && row["step1"].ToString() != "")
                {
                    model.step1 = int.Parse(row["step1"].ToString());
                }
                if (row["step2"] != null && row["step2"].ToString() != "")
                {
                    model.step2 = int.Parse(row["step2"].ToString());
                }
                if (row["step3"] != null && row["step3"].ToString() != "")
                {
                    model.step3 = int.Parse(row["step3"].ToString());
                }
                if (row["bcity"] != null)
                {
                    model.bcity = row["bcity"].ToString();
                }
                if (row["gcity"] != null)
                {
                    model.gcity = row["gcity"].ToString();
                }
                if (row["cumname"] != null)
                {
                    model.cumname = row["cumname"].ToString();
                }
                if (row["cumcode"] != null)
                {
                    model.cumcode = row["cumcode"].ToString();
                }
                if (row["hardremark"] != null)
                {
                    model.hardremark = row["hardremark"].ToString();
                }
                if (row["saleman"] != null)
                {
                    model.saleman = row["saleman"].ToString();
                }
                if(row["gocheckremark"]!=null)
                {
                    model.gocheckremark = row["gocheckremark"].ToString();
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select id,hardwareno,initno,hardno,wrlid,wrlno,loadno,cjono,wrldate,inspectiondate,loadremark,cjoremark,initcheck,initremark,hardwarefinish,boxcount,outstime,tallyremark,flag1,flag2,flag3,flag4,step1,step2,step3,bcity,gcity,cumname,cumcode,hardremark,saleman,gocheckremark ");
            strSql.Append(" FROM Hardware ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" id,hardwareno,initno,hardno,wrlid,wrlno,loadno,cjono,wrldate,inspectiondate,loadremark,cjoremark,initcheck,initremark,hardwarefinish,boxcount,outstime,tallyremark,flag1,flag2,flag3,flag4,step1,step2,step3,bcity,gcity,cumname,cumcode,hardremark,saleman,gocheckremark ");
            strSql.Append(" FROM Hardware ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM Hardware ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.id desc");
            }
            strSql.Append(")AS Row, T.*  from Hardware T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "Hardware";
            parameters[1].Value = "id";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod
		#region  ExtensionMethod

        /// <summary>
        /// 根据称重ID插入数据
        /// </summary>
        /// <returns></returns>
        public bool HardInsert(int wrlid, bool check)
        {
            bool hard = true;

            string querysql = "select * from Hardware where wrlid=" + wrlid.ToString();
            DataTable dt = DbHelperSQL.Query(querysql.ToString()).Tables[0];

            int boxcount = 0;
            string countsql = "select count(1) from (select barcodevalue from BarCode where InStrorageID=" + wrlid.ToString() + " group by barcodevalue) t1";
            DataTable d = DbHelperSQL.Query(countsql.ToString()).Tables[0];
            if (d != null && d.Rows.Count == 1)
            {
                boxcount = int.Parse(d.Rows[0][0].ToString());
            }
            Model.Hardware m = new Model.Hardware();
            if (dt != null && dt.Rows.Count >= 1)
            {
                m = GetModel(int.Parse(dt.Rows[0]["id"].ToString()));
                m.step1 = 0;
                m.flag1 = "A";
                if (check == true)
                {
                    m.step3 = 0;
                }
                else
                {
                    m.initremark = "";
                    m.tallyremark = "";
                    m.hardremark = "";
                    m.step3 = -1;
                }
                m.boxcount = boxcount.ToString();
                hard = Update(m);

            }
            else
            {
                if (check == true)
                {
                    DataLib.Model.InStorage mi = new DataLib.Model.InStorage();
                    DataLib.BLL.InStorage bi = new DataLib.BLL.InStorage();

                    mi = bi.GetModel(wrlid);
                    m.step1 = 0;
                    m.wrlid = wrlid;
                    m.wrlno = mi.wrlno;
                    if (mi.outid == 0)
                    {
                        Model.Cjo mc = new Model.Cjo();
                        Model.LoadNum ml = new Model.LoadNum();
                        Cjo bc = new Cjo();
                        LoadNum bl = new LoadNum();
                        mc = bc.GetModel(mi.cjoid);
                        ml = bl.GetModel(mc.loadnumid);
                        m.loadno = mc.loadnum;
                        m.cjono = mc.cjono;
                        m.cumcode = mc.customercode;
                        m.cumname = mc.customername;
                         m.cjoremark = ml.Memo;
                        //m.cjoremark = mi.remark;
                        m.bcity = mc.belogcity;
                        m.gcity = mc.graphiccity;
                        m.wrldate = ((DateTime)mc.cjocolldate).ToString("yyyy-MM-dd");
                        Accounts.Bus.User u = new Accounts.Bus.User(mc.sealman_create.Trim());
                        if (u != null)
                            m.saleman = u.TrueName;
                    }
                    else
                    {
                        OutStorage bo = new OutStorage();
                        Model.OutStorage mo = new Model.OutStorage();
                        mo = bo.GetModel(mi.outid);
                        if (mo != null)
                        {
                            m.loadno = mo.VLoadNum;
                            m.cjono = mo.outStorageNo;
                            m.cumcode = "--";
                            m.cumname = mo.inDepart + mo.OutDepart;
                            m.bcity = mo.belogarea;
                            m.gcity = mo.graphicCity;
                            m.wrldate = ((DateTime)mo.outStorageDate).ToString("yyyy-MM-dd");
                            Accounts.Bus.User u = new Accounts.Bus.User(mo.Operator);
                            if (u != null)
                                m.saleman = u.TrueName;
                        }
                    }
                    m.step3 = 0;
                    m.flag1 = "A";
                    m.boxcount = boxcount.ToString();
                   
                    //

                    Add(m);
                }
            }

            return hard;
        }

               /// <summary>
        /// 根据称重ID插入数据
        /// </summary>
        /// <returns>如果为真则存在，如果为假不存在</returns>
        public bool IsHardCheck(int wrlid)
        {
            bool hard = false;
            string strsql = "select * FROM Hardware where step3=0 and wrlid=" + wrlid.ToString();
            DataTable dt = DbHelperSQL.Query(strsql.ToString()).Tables[0];
            if (dt != null && dt.Rows.Count >= 1)
            {
                hard = true;
            }
            return hard;
        }



        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(DataLib.Model.Hardware model)
        {
            StringBuilder strSql = new StringBuilder();
            tab_Num tab = new tab_Num();
            model.hardwareno = tab.GenNo("E", "Hardware");
            strSql.Append("insert into Hardware(");
            strSql.Append("hardwareno,initno,hardno,wrlid,wrlno,loadno,cjono,wrldate,inspectiondate,loadremark,cjoremark,initcheck,initremark,hardwarefinish,boxcount,outstime,tallyremark,flag1,flag2,flag3,flag4,step1,step2,step3,bcity,gcity,cumname,cumcode,hardremark,saleman,gocheckremark)");
            strSql.Append(" values (");
            strSql.Append("@hardwareno,@initno,@hardno,@wrlid,@wrlno,@loadno,@cjono,@wrldate,@inspectiondate,@loadremark,@cjoremark,@initcheck,@initremark,@hardwarefinish,@boxcount,@outstime,@tallyremark,@flag1,@flag2,@flag3,@flag4,@step1,@step2,@step3,@bcity,@gcity,@cumname,@cumcode,@hardremark,@saleman,@gocheckremark)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@hardwareno", SqlDbType.VarChar,20),
					new SqlParameter("@initno", SqlDbType.VarChar,20),
					new SqlParameter("@hardno", SqlDbType.VarChar,20),
					new SqlParameter("@wrlid", SqlDbType.Int,4),
					new SqlParameter("@wrlno", SqlDbType.VarChar,200),
					new SqlParameter("@loadno", SqlDbType.VarChar,100),
					new SqlParameter("@cjono", SqlDbType.VarChar,100),
					new SqlParameter("@wrldate", SqlDbType.VarChar,30),
					new SqlParameter("@inspectiondate", SqlDbType.VarChar,30),
					new SqlParameter("@loadremark", SqlDbType.VarChar,200),
					new SqlParameter("@cjoremark", SqlDbType.VarChar,200),
					new SqlParameter("@initcheck", SqlDbType.VarChar,200),
					new SqlParameter("@initremark", SqlDbType.VarChar,200),
					new SqlParameter("@hardwarefinish", SqlDbType.VarChar,200),
					new SqlParameter("@boxcount", SqlDbType.VarChar,20),
					new SqlParameter("@outstime", SqlDbType.VarChar,30),
					new SqlParameter("@tallyremark", SqlDbType.VarChar,300),
					new SqlParameter("@flag1", SqlDbType.VarChar,50),
					new SqlParameter("@flag2", SqlDbType.VarChar,50),
					new SqlParameter("@flag3", SqlDbType.VarChar,50),
					new SqlParameter("@flag4", SqlDbType.VarChar,50),
					new SqlParameter("@step1", SqlDbType.Int,4),
					new SqlParameter("@step2", SqlDbType.Int,4),
					new SqlParameter("@step3", SqlDbType.Int,4),
					new SqlParameter("@bcity", SqlDbType.VarChar,20),
					new SqlParameter("@gcity", SqlDbType.VarChar,20),
					new SqlParameter("@cumname", SqlDbType.VarChar,100),
					new SqlParameter("@cumcode", SqlDbType.VarChar,100),
					new SqlParameter("@hardremark", SqlDbType.VarChar,200),
					new SqlParameter("@saleman", SqlDbType.VarChar,50),
                    new SqlParameter("@gocheckremark",SqlDbType.VarChar,200)};
            parameters[0].Value = model.hardwareno;
            parameters[1].Value = model.initno;
            parameters[2].Value = model.hardno;
            parameters[3].Value = model.wrlid;
            parameters[4].Value = model.wrlno;
            parameters[5].Value = model.loadno;
            parameters[6].Value = model.cjono;
            parameters[7].Value = model.wrldate;
            parameters[8].Value = model.inspectiondate;
            parameters[9].Value = model.loadremark;
            parameters[10].Value = model.cjoremark;
            parameters[11].Value = model.initcheck;
            parameters[12].Value = model.initremark;
            parameters[13].Value = model.hardwarefinish;
            parameters[14].Value = model.boxcount;
            parameters[15].Value = model.outstime;
            parameters[16].Value = model.tallyremark;
            parameters[17].Value = model.flag1;
            parameters[18].Value = model.flag2;
            parameters[19].Value = model.flag3;
            parameters[20].Value = model.flag4;
            parameters[21].Value = model.step1;
            parameters[22].Value = model.step2;
            parameters[23].Value = model.step3;
            parameters[24].Value = model.bcity;
            parameters[25].Value = model.gcity;
            parameters[26].Value = model.cumname;
            parameters[27].Value = model.cumcode;
            parameters[28].Value = model.hardremark;
            parameters[29].Value = model.saleman;
            parameters[30].Value = model.gocheckremark;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }

		#endregion  ExtensionMethod
	}
}

